package uk.co.richardwkirk.parkrun.android.storage;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class AthleteOpenHelper extends SQLiteOpenHelper {

	private static final int DATABASE_VERSION = 6;

	public static final String ATHLETE_LIST_TABLE_NAME = "athlete_list";

	public static final String ATHLETE_ID = "_id";
	public static final String ATHLETE_NAME = "name";
	public static final String ATHLETE_CLUB = "club";
	public static final String ATHLETE_DATA = "data";

	private static final String ATHLETE_LIST_TABLE_CREATE = "CREATE TABLE " + ATHLETE_LIST_TABLE_NAME 
			+ " (" + ATHLETE_ID + " INTEGER, "
			+ ATHLETE_NAME + " TEXT, "
			+ ATHLETE_CLUB + " TEXT, "
			+ ATHLETE_DATA + " TEXT);";

	AthleteOpenHelper(Context context) {
		super(context, ATHLETE_LIST_TABLE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(ATHLETE_LIST_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(AthleteOpenHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + ATHLETE_LIST_TABLE_NAME);
		onCreate(db);
	}
}
